package com.menglei.dailytasks.m0713;

import android.app.Notification;
import android.app.NotificationChannel;
import android.content.Context;
import android.os.Build;

import androidx.annotation.RequiresApi;


import com.menglei.dailytasks.R;

import static android.content.Context.NOTIFICATION_SERVICE;

public class NotificationManager {

    @RequiresApi(api = Build.VERSION_CODES.O)
    public static void addNotification(Context context, String channelId, String title, String content) {
        //1，获取通知管理器
        android.app.NotificationManager notificationManager = (android.app.NotificationManager) context.getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
        //2，通知渠道
        NotificationChannel channel = new NotificationChannel(channelId, "通知管理", android.app.NotificationManager.IMPORTANCE_HIGH);
        notificationManager.createNotificationChannel(channel);
        Notification.Builder builder = new Notification.Builder(context, channelId);//这里要和注册的渠道id要一致
        builder.setSmallIcon(R.drawable.ic_launcher_foreground)
                .setChannelId(channelId)
                .setContentTitle(title)
                .setContentText(content);
        notificationManager.notify(1, builder.build());
    }
}
